home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / TimGA 1.2.1 / .cp / CGeneralDialog.cp < prev    next >
Encoding:
Text File  |  1997-07-16  |  5.6 KB  |  217 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CGeneralDialog.cp        ©1995-97 Timo Eloranta        All rights reserved.
  3. // ===========================================================================
  4.  
  5. #include "CGeneralDialog.h"
  6. #include "GraphGA_PaneIDs.h"
  7.  
  8. #include <LString.h>
  9. #include <PP_Messages.h>
  10.  
  11. #include <LCaption.h>
  12. #include <LGAEditField.h>
  13. #include <LGAPushButton.h>
  14.  
  15. #include "CAGASlider.h"
  16.  
  17. // ---------------------------------------------------------------------------
  18. //        • CGeneralDialog
  19. //
  20. //          Called by:    URegistrar::CreateObject
  21. // ---------------------------------------------------------------------------
  22.  
  23. CGeneralDialog::CGeneralDialog( LStream *inStream )
  24.     : LGADialogBox( inStream )
  25. {
  26. }
  27.  
  28. // ---------------------------------------------------------------------------
  29. //        • InitDialog
  30. //
  31. //          Called by:    CGraphGAApp::ObeyCommand
  32. // ---------------------------------------------------------------------------
  33.  
  34. void
  35. CGeneralDialog::InitDialog()
  36. {
  37.     mPopCapt        = (LCaption *) this -> FindPaneByID( capt_Pop );
  38.     mGridCapt        = (LCaption *) this -> FindPaneByID( capt_Grid );
  39.     
  40.     mFactoryButton    = (LGAPushButton *) this -> FindPaneByID( but_FactorySettings );
  41.         
  42.     mTicksEdit        = (LGAEditField *) this -> FindPaneByID( edit_Ticks );
  43.     
  44.     mPopSlider        = (CAGASlider *) this -> FindPaneByID( slid_Pop );
  45.     mGridSlider        = (CAGASlider *) this -> FindPaneByID( slid_Grid );
  46.  
  47.     mTicksEdit -> Enable();
  48.     mTicksEdit -> Activate();
  49.     mTicksEdit -> SelectAll();
  50.  
  51.     if ( mFactoryButton)
  52.         mFactoryButton -> AddListener( this );
  53.  
  54.     if ( mPopSlider )
  55.         mPopSlider -> AddListener( this );
  56.  
  57.     if ( mGridSlider )
  58.         mGridSlider -> AddListener( this );
  59. }
  60.  
  61. // ---------------------------------------------------------------------------
  62. //        • SetValues
  63. //
  64. //          Called by:    CGraphGAApp::ObeyCommand
  65. // ---------------------------------------------------------------------------
  66.  
  67. void
  68. CGeneralDialog::SetValues( SGeneral &inGeneral )
  69. {
  70.     if ( mTicksEdit )
  71.         mTicksEdit -> SetValue( inGeneral.spendTime );
  72.  
  73.     if ( mPopCapt )
  74.         mPopCapt -> SetValue( inGeneral.sizePop );
  75.     if ( mPopSlider )
  76.         mPopSlider -> SetValue( inGeneral.sizePop );
  77.  
  78.     if ( mGridCapt )
  79.         SetGridValue( inGeneral.sizeGrid );
  80.     if ( mGridSlider )
  81.         mGridSlider -> SetValue( inGeneral.sizeGrid );
  82.         
  83. }
  84.  
  85. // ---------------------------------------------------------------------------
  86. //        • SetGridValue    (PRIVATE)
  87. //
  88. //          Called by:    CGeneralDialog::SetValues
  89. //                        CGeneralDialog::ListenToMessage
  90. // ---------------------------------------------------------------------------
  91.  
  92. void
  93. CGeneralDialog::SetGridValue( Int16 inValue )
  94. {
  95.     LStr255        theNbrString( (Int32) inValue );
  96.     LStr255        theString( theNbrString );
  97.  
  98.     theString.Append( "\p x " ); 
  99.     theString.Append( theNbrString ); 
  100.  
  101.     mGridCapt    -> SetDescriptor( theString );
  102. }
  103.  
  104. // ---------------------------------------------------------------------------
  105. //        • GetValues
  106. //
  107. //          Called by:    CGraphGAApp::SetGeneralFromDialog
  108. // ---------------------------------------------------------------------------
  109.  
  110. void
  111. CGeneralDialog::GetValues( SGeneral &outGeneral )
  112. {
  113.     if ( mPopCapt )
  114.         outGeneral.sizePop = mPopCapt -> GetValue();
  115.     if ( mGridSlider )
  116.         outGeneral.sizeGrid = mGridSlider -> GetValue();
  117.     if ( mTicksEdit )
  118.         outGeneral.spendTime = mTicksEdit -> GetValue();
  119. }
  120.  
  121. // ---------------------------------------------------------------------------
  122. //        • ListenToMessage
  123. //
  124. //          Called by:    LBroadcaster::BroadcastMessage
  125. // ---------------------------------------------------------------------------
  126.  
  127. void
  128. CGeneralDialog::ListenToMessage(
  129.     MessageT    inMessage, 
  130.     void        *ioParam )
  131. {
  132.     switch ( inMessage ) {
  133.  
  134.         case slid_Pop:
  135.             if ( mPopCapt ) {
  136.                 mPopCapt -> SetValue( *(Int32 *) ioParam );
  137.                 mPopCapt -> Draw( nil );
  138.                 AdjustFactoryButton();
  139.             }
  140.             break;
  141.  
  142.         case slid_Grid:
  143.             if ( mGridCapt ) {
  144.                 SetGridValue( *(Int32 *) ioParam );
  145.                 mGridCapt -> Draw( nil );
  146.                 AdjustFactoryButton();
  147.             }
  148.             break;
  149.             
  150.         case msg_FactorySettings:
  151.             SetDefaultValues();
  152.             break;
  153.             
  154.         default:    
  155.             LGADialogBox::ListenToMessage( inMessage, ioParam );
  156.             break;
  157.     }
  158. }
  159.  
  160. // ---------------------------------------------------------------------------
  161. //        • SetDefaultValues    (PRIVATE)
  162. //
  163. //          Called by:    CGeneralDialog::ListenToMessage
  164. // ---------------------------------------------------------------------------
  165.  
  166. void
  167. CGeneralDialog::SetDefaultValues( )
  168. {
  169.     if ( mTicksEdit )
  170.         mTicksEdit -> SetValue( DEFAULT_SPEND_TIME );
  171.  
  172.     if ( mPopSlider )
  173.         mPopSlider -> SetValue( DEFAULT_POP_SIZE );
  174.  
  175.     if ( mGridSlider )
  176.         mGridSlider -> SetValue( DEFAULT_GRID_SIZE );
  177. }
  178.         
  179. // ---------------------------------------------------------------------------
  180. //        • AdjustFactoryButton
  181. //
  182. //          Called by:    CGeneralDialog::ListenToMessage
  183. // ---------------------------------------------------------------------------
  184.  
  185. void
  186. CGeneralDialog::AdjustFactoryButton( )
  187. {
  188.     if ( (mPopCapt -> GetValue())        == DEFAULT_POP_SIZE    &&
  189.          (mGridSlider -> GetValue())    == DEFAULT_GRID_SIZE &&
  190.          (mTicksEdit -> GetValue())        == DEFAULT_SPEND_TIME )
  191.             mFactoryButton -> Disable();
  192.     else
  193.         if ( ! mFactoryButton -> IsEnabled() ) 
  194.              mFactoryButton -> Enable();
  195. }
  196.  
  197. // ---------------------------------------------------------------------------
  198. //        • FindCommandStatus
  199. //
  200. //          Called by:    LCommander::ProcessCommandStatus
  201. // ---------------------------------------------------------------------------
  202. //    Disable all menu items except for the one which opens the About box.
  203.  
  204. void
  205. CGeneralDialog::FindCommandStatus(
  206.     CommandT    inCommand,
  207.     Boolean        &outEnabled,
  208.     Boolean&    /* outUsesMark */,
  209.     Char16&        /* outMark */,
  210.     Str255        /* outName */)
  211. {
  212.     outEnabled = false;
  213.     if (inCommand == cmd_About) {
  214.         outEnabled = true;
  215.     }
  216. }
  217.